home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / gedeiffel / tools / eiffel / arexx / finder.ged < prev    next >
Text File  |  1999-11-29  |  5KB  |  185 lines

  1. /*
  2.  * finder.ged -- Find and load class under cursor.
  3.  *
  4.  * Copyright (C) 1999 Thomas Aglassiner <agi@sbox.tu-graz.ac.at>
  5.  * Freeware. Use at your own risk.
  6.  */
  7. version_info = "$VER: finder.ged 1.2 (4.3.99)"
  8.  
  9. OPTIONS RESULTS                             /* enable return codes     */
  10.  
  11. if (LEFT(ADDRESS(), 6) ~= "GOLDED") then    /* not started by GoldEd ? */
  12.     address 'GOLDED.1'
  13.  
  14. 'LOCK CURRENT RELEASE=4'                    /* lock GUI, gain access   */
  15.  
  16. if (RC ~= 0) then
  17.     exit
  18.  
  19. OPTIONS FAILAT 21
  20.  
  21. SIGNAL ON SYNTAX                            /* ensure clean exit       */
  22.  
  23. /* ------------------------ INSERT YOUR CODE HERE: ------------------- */
  24.  
  25. 'QUERY WORD VAR=class_name'
  26.  
  27. legal_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890'
  28. IF (Strip(Upper(class_name), 'B', legal_letters) = '') ,
  29.    & (class_name ~= '') THEN ,
  30. DO
  31.    temporary_file = 't:finder.tmp'
  32.  
  33.    ADDRESS COMMAND 'rx >nil: golded:tools/eiffel/arexx/execute.rexx Port=SMALLEIFFEL.1 ' || ,
  34.                    '"finder >' || temporary_file || ' ' || class_name || '"'
  35.  
  36.    class_found = 0
  37.    IF RC = 0 THEN DO
  38.       IF OPEN('full_path', temporary_file, 'read') THEN DO
  39.          class_found = 1
  40.          class_path = READLN('full_path')
  41.          'WINDOW FORCE USE="' || class_path || '"'
  42.          CALL CLOSE('full_path')
  43.       END
  44.    END
  45.  
  46.    IF ~class_found THEN DO
  47.       'REQUEST STATUS=""'
  48.       'REQUEST TITLE="Find Class Error" PROBLEM="Class ''' || class_name || ''' not found."'
  49.    END
  50.  
  51. END
  52. ELSE DO
  53.    'REQUEST TITLE="Find Class Error" PROBLEM="Cursor must be placed over a proper class name."'
  54. END
  55.  
  56.  
  57. /* ---------------------------- END OF YOUR CODE --------------------- */
  58.  
  59. 'UNLOCK' /* VERY important: unlock GUI */
  60.  
  61. exit
  62.  
  63. SYNTAX:
  64.  
  65.    SAY "Syntax error line" SIGL ":" ERRORTEXT(RC)
  66.    'UNLOCK'
  67.  
  68.    exit
  69.  
  70. /***** ugly/convert_amiga_path_to_uri **************************************
  71.  * NAME
  72.  *   convert_amiga_path_to_uri -- Convert path from Amiga to URI style
  73.  * FUNCTION
  74.  *   Convert path from Amiga to URI style. The following conversion rules
  75.  *   are applied:
  76.  *
  77.  *   - Device names are transformed from e.g. "ram:" to "/ram/"
  78.  *   - Leading "/"'s replaced by "../"
  79.  *   - All "//"'s are replaced by "/../"
  80.  * INPUTS
  81.  *   amiga_path - Amiga style path
  82.  * RESULT
  83.  *   Path in URI style
  84.  * BUGS
  85.  *   The input path is not validated for correctness. In such a case the
  86.  *   result will also be invalid.
  87.  * EXAMPLES
  88.  *   "ram:"           -> "/ram/"
  89.  *   "ram:sepp"       -> "/ram/sepp"
  90.  *   "sepp//resi"     -> "sepp/../resi"
  91.  *   "ram:sepp//resi" -> "/ram/sepp/../resi"
  92.  *   "//resi/hugo"    -> "../../resi/hugo"
  93.  *   "//resi//hugo"   -> "../../resi/../hugo
  94.  **************************************************************************/
  95. convert_amiga_path_to_uri : PROCEDURE
  96.     PARSE ARG amiga_path
  97.  
  98.     uri = ''
  99.  
  100.     /* Extract device name from Amigapath (if there is any) */
  101.     device = ''
  102.     IF (POS(':', amiga_path) > 0) THEN DO
  103.         PARSE VAR amiga_path device ':' path_part
  104.         amiga_path = path_part
  105.     END
  106.  
  107.     /* Convert leading "/" to "../" */
  108.     DO WHILE (LEFT(amiga_path, 1) = '/')
  109.         amiga_path = DELSTR(amiga_path, 1, 1)
  110.         uri = uri || '../'
  111.     END
  112.  
  113.     uri = uri || amiga_path
  114.  
  115.     /* Convert '//' inside string to '/../' */
  116.     DO WHILE (POS('//', uri) > 0)
  117.         PARSE VAR uri before '//' after
  118.         uri = before || '/../' || after
  119.     END
  120.  
  121.     /* Add device name in Unix-style;
  122.      * 'ram:' becomes '/ram/' */
  123.     IF (device ~= '') THEN DO
  124.         uri = '/' || device || '/' || uri
  125.     END
  126.  
  127.     RETURN uri
  128.  
  129. /***** ugly/convert_uri_to_amiga_path **************************************
  130.  * NAME
  131.  *   convert_uri_to_amiga_path -- Convert path from URI to Amiga style
  132.  * SYNOPSIS
  133.  *   amiga_path = convert_uri_to_amiga_path( uri )
  134.  * FUNCTION
  135.  *   Convert path from URI to Amiga style. The following conversion rules
  136.  *   are applied:
  137.  *
  138.  *   - Remove leading './'
  139.  *   - Replace every leading '../' by '/'
  140.  *   - Replace every '/../' by '//'
  141.  *   - Replace every '~' by '%7E'
  142.  * INPUTS
  143.  *   uri - URI style path
  144.  * RESULT
  145.  *   amiga_path - Amiga style path
  146.  * BUGS
  147.  *   The input path is not validated for correctness. In such a case the
  148.  *   result will also be invalid.
  149.  *
  150.  *   Devices in URI style are not handled.
  151.  **************************************************************************/
  152. convert_uri_to_amiga_path : PROCEDURE
  153.     PARSE ARG uri
  154.  
  155.     amiga_path = ''
  156.  
  157.     /* Remove leading "./" */
  158.     IF (LEFT(uri, 2) = './')
  159.         uri = DELSTR(uri, 1, 2)
  160.     END
  161.  
  162.     /* Replace leading "../" by "/" */
  163.     DO WHILE (LEFT(uri, 3) = '../')
  164.         uri = DELSTR(uri, 1, 3)
  165.         amiga_path = amiga_path || '/'
  166.     END
  167.  
  168.     amiga_path = amiga_path || uri
  169.  
  170.     /* Replace '/../' inside string by '//' */
  171.     DO WHILE (POS('//', uri) > 0)
  172.         PARSE VAR uri before '/../' after
  173.         amiga_path = before || '//' || after
  174.     END
  175.  
  176.     /* Replace '~' by '%7E' */
  177.     DO WHILE (POS('~', uri) > 0)
  178.         PARSE VAR uri before '~' after
  179.         amiga_path = before || '%7E' || after
  180.     END
  181.  
  182.     RETURN amiga_path
  183.  
  184.  
  185.